from celery_tasks.main import celery_app
from celery_tasks.sms.yuntongxun.sms import CCP

import logging
logger = logging.getLogger('django')
@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, security_code):
    ccp = CCP()
    # ccp.send_template_sms('18516952650', ['1234', 5], 1)
    try:
        send_sms = ccp.send_template_sms(mobile, [security_code, 5], 1)
    except Exception as e:
        logger.error(e)
    else:
        if send_sms != 0:
            # 短信发送失败
            logger.error('短信验证码发送失败：[mobile: %s sms_code: %s]' % (mobile, security_code))
        else:
            logger.info('短信验证码发送成功：[mobile: %s sms_code: %s]' % (mobile, security_code))
